;**********************************************;
;* Project Title: Monopoly                    *;
;*                                            *;
;**********************************************;

; Best viewed with a tab width of 9.


	IDEAL
	P386N
	DOSSEG
	MODEL	small
	STACK	1024



;==========================================================================
;                               Data segment
;==========================================================================[
	DATASEG

;---------------------------------------------------------------------
; Working Area
;---------------------------------------------------------------------
exitStatus	db	0
outbuff		db	256 dup(?)
two		dw	2
click		dw	0

;---------------------------------------------------------------------         
; Message variables
;---------------------------------------------------------------------          
wel_msg         db      'Welcome to the '			; welcome message
prog_name	db	'j-monopoly-asm',0			; program name
key_msg         db      'Press any key to continue',0		; 2nd line

wof_msg         db      '$$$ Monopoly v0.1 $$$',0		; Game Title

confirm_exit	db	'Are you sure you want to quit? (y/n)',0

askname1	db	'Enter Player 1 Name: ',0
askname2	db	'Enter Player 2 Name: ',0

turn_msg	db	'Current Turn:',0
cash_msg	db	'Cash:',0
asset_msg	db	'Assets:',0

plyr1name	db	20 dup(0)
plyr2name	db	20 dup(0)

;---------------------------------------------------------------------         
; Mouse Coordinate Helper
;---------------------------------------------------------------------{{{
bar_height	dw	14
bar_coord	dw	032, 048, 064, 080, 096,
		dw	112, 128, 144, 160, 176,
		dw	192, 224, 240, 256, 272,
		dw	288, 304, 320, 336, 352,
		dw	368, 384, 400, 416, 432,
		dw	448, 464, 456
mouse_action	db	28 dup(0)
;}}} 

;---------------------------------------------------------------------
; Space Names
;---------------------------------------------------------------------{{{
space_1		db	'Go',0	;Array of 11 bytes each
space_2		db	'Space1',0
space_3		db	'Space2',0
space_4		db	'Space3',0
space_5		db	'Util4',0
space_6		db	'Place5',0
space_7		db	'Place6',0
space_8		db	'Place7',0
space_9		db	'Jail8',0
space_10	db	'Street9',0
space_11	db	'Street10',0
space_12	db	'Street11',0
space_13	db	'Util12',0
space_14	db	'Space13',0
space_15	db	'Space14',0
space_16	db	'Space15',0
space_17	db	'Chance16',0
space_18	db	'Place17',0
space_19	db	'Place18',0
space_20	db	'Place19',0
space_21	db	'Util20',0
space_22	db	'Street21',0
space_23	db	'Street22',0
space_24	db	'Street23',0
;}}}	
	
	
	
	
	
;---------------------------------------------------------------------          
; Message variables
;---------------------------------------------------------------------{{{          
	
	lbr	db	10,13,0,'$'
	dashed	db	'---------------------------',0,10,13,'$'
;}}}

;---------------------------------------------------------------------          
; Turn setup and dice variables
;---------------------------------------------------------------------{{{          
	
;public 	curr_plyr,curr_cash,curr_assets,curr_jailed
;public	plyrA_cash,plyrB_cash
;public	plyrA_assets,plyrB_assets,plyrA_util,plyrB_util,plyrA_space,plyrB_space
;public	plyrA_jailed,plyrB_jailed
;public	dice_roll
	
	curr_plyr	db	0	; 0 or 1
	curr_cash	dw	00
	curr_assets	dw	00
	curr_jailed	db	0
	plyrA_cash	dw	500
	plyrB_cash	dw	500
	plyrA_assets	dw	0
	plyrB_assets	dw	0
	plyrA_util	db	0
	plyrB_util	db	0
	plyrA_space	db	0
	plyrB_space	db	0
	plyrA_jailed	db	0	;2 when newly set; 1 on next turn; 0 next next turn
	plyrB_jailed	db	0
	dice_roll	db	
;}}}


;---------------------------------------------------------------------          
; Turn setup messages (TEMP FRONTEND)
;---------------------------------------------------------------------{{{          
	
	plyrA_msg	db	'Player A.',0, 10, 13, '$'
	plyrB_msg	db	'Player B.',0, 10, 13, '$'
	;cash_msg		db	'Cash: ',0,            '$'
	assets_msg	db	'Assets: ',0,          '$'
	jailed_msg	db	'You are still in jail! Miss this turn.',0,10,13,'$'
	
;}}}


;---------------------------------------------------------------------          
; Board variables
;---------------------------------------------------------------------{{{  
	
;public	curr_space,curr_type,curr_owner,curr_level		;Current turn variables
;public	space_type,space_name,space_owner,space_level	;Arrays for space info
;public	buy_price,upgrade_price,rent_price			;Arrays for space prices
	
	spaces		equ	24d			;Spaces that can be visited by dice roll.
	curr_space	db				;Current space id for current player
	curr_type	db
	curr_owner	db
	curr_level	db	
	
	space_type	db	0,1,1,1			;0=go,1=property,2=util,3=jail,4=chance 
			db	2,1,1,1
			db	3,1,1,1
			db	2,1,1,1
			db	4,1,1,1
			db	2,1,1,1
	
	space_name	db	'Go0     ',0,10,13,'$'	;Array of 11 bytes each
			db	'Space1  ',0,10,13,'$'
			db	'Space2  ',0,10,13,'$'
			db	'Space3  ',0,10,13,'$'
			db	'Util4   ',0,10,13,'$'
			db	'Place5  ',0,10,13,'$'
			db	'Place6  ',0,10,13,'$'
			db	'Place7  ',0,10,13,'$'
			db	'Jail8   ',0,10,13,'$'
			db	'Street9 ',0,10,13,'$'
			db	'Street10',0,10,13,'$'
			db	'Street11',0,10,13,'$'
			db	'Util12  ',0,10,13,'$'
			db	'Space13 ',0,10,13,'$'
			db	'Space14 ',0,10,13,'$'
			db	'Space15 ',0,10,13,'$'
			db	'Chance16',0,10,13,'$'
			db	'Place17 ',0,10,13,'$'
			db	'Place18 ',0,10,13,'$'
			db	'Place19 ',0,10,13,'$'
			db	'Util20  ',0,10,13,'$'
			db	'Street21',0,0,10,13,'$'
			db	'Street22',0,0,10,13,'$'
			db	'Street23',0,0,10,13,'$'
	
	
	space_owner	db	24 dup (2)	 	;0,1 = player; 2 = not owned
			db	
	space_level	db	24 dup (0)		;0 = house, 1 = condo, 2 = hotel
	buy_price	db	0,20,20,30
			db	50,40,40,50
			db	0,60,60,70
			db	50,80,80,90
			db	0,100,100,110
			db	50,120,120,140
	upgrade_price	db	0,10,10,15
			db	0,20,20,25
			db	0,30,30,35
			db	0,40,40,45
			db	0,50,50,55
			db	0,60,60,70
	rent_price	db	0,1,1,2			;Action_util_rent doesn't actually use value here.
			db	10,3,3,4
			db	0,5,5,6
			db	10,7,7,8
			db	0,9,9,10
			db	10,11,11,12
	
;}}}

;---------------------------------------------------------------------          
; Roll dice messages (TEMP FRONTEND)
;---------------------------------------------------------------------{{{          
	currspace_msg	db	'You are now at space #',0,'$'
	roll_msg		db	'Press enter to roll dice.',0,10,13,'$'	; 0 or 1
	result_msg	db	'The dice shows: ',0,'$'
	
	
;}}}

;---------------------------------------------------------------------          
; Move piece messages (TEMP FRONTEND)
;---------------------------------------------------------------------{{{          
	newspace_msg	db	'Your new space is #',0,'$'	
	
;}}}

;---------------------------------------------------------------------          
;Exit messages (TEMP FRONTEND)
;---------------------------------------------------------------------{{{          
	exit_msg		db	'The final result is:',0,10,13,'$'
	winner_msg	db	'The winner of the game is ',0,'$'
	tie_msg		db	'no-one.',0,10,13,'$'
	score_msg	db	'The winner got a score of: ',0,'$'

;}}}

;---------------------------------------------------------------------          
; Action messages (TEMP FRONTEND)
;---------------------------------------------------------------------{{{          
	spacetype_msg	db	'The space type is ',0,'$'
	currowner_msg	db	'The owner of this space is ',0,'$'
	spacelevel_msg	db	'The level of this space is ',0,'$'
	
	
	
	ask_upg_msg	db	'You own this space. Do you want to upgrade? Amount: ',0,'$'
	full_upg_msg	db	'Your space already has a hotel on it! Yay!',0,10,13,'$'
	pay_rent_msg	db	'You must pay rent! Amount: ',0,'$'
	ask_buy_msg	db	'Do you want to buy this space? Amount:',0,'$'
	
	utilown_msg	db	'You already own this utility.',0,10,13,'$'
	
	go_msg		db	'Go space! Earn 50 dollars.',0,10,13,'$'
	utility_msg	db	'This is a utility.',0,10,13,'$'
	jail_msg		db	'Miss a turn in jail!',0,10,13,'$'
	goodluck_msg	db	'Congratulations! You have won money from the lottery: ',0,'$'
	badluck_msg	db	'Bad luck! You have lost 50 dollars due to robbery!',0,10,13,'$'
	
;}}}

;---------------------------------------------------------------------          
; Cash/yesno variables (TEMP FRONTEND)
;---------------------------------------------------------------------{{{          
	overflow_msg	db	'Overflow!',0,10,13,'$'
	flag_var		db
	
;}}}	




;==========================================================================
;                                Macros
;==========================================================================[

INCLUDE "macros.asm"

MASM
;--------------------------------------------------------------------------
; displays message
;--------------------------------------------------------------------------{{
;message	macro	msg

	;push	ax		; saves previous contents of ax into stack
	;push	dx		; saves previous contents of dx into stack

	;lea	dx, msg		; displays message
	;mov	ah, 09h
	;int	21h

	;pop	dx		; retrieves previous contents of dx from stack
	;pop	ax		; retrieves previous contents of ax from stack

;endm
;}}

;]


;==========================================================================
;                               Code segment
;==========================================================================[

IDEAL
CODESEG
assume	ds:@data, es:@data
;----- From bintodec.obj

	EXTRN	bintoasc:proc 

;----- From strio.obj

	EXTRN	StrWrite:proc, StrRead:proc

;----- From strings.obj

	EXTRN	StrLength:proc	


;==========================================================================
;                               Main Section
;=========================================================================={{
extrn 	dispx:proc
extrn	rand:proc
;extrn	initialize:proc
;extrn	maincontrol:proc
;extrn	plystatus:proc
;extrn	outmsg:proc

start:
	mov	ax, @data		; initialise data segment
	mov	ds, ax
	mov	es, ax

set_screen:
	mov	ah, 00h		; set resolution to 640 x 480
	mov	al, 12h		; 16 colors
	int	10h

clear_registers:
	call	clear_reg	; clears ax, bx, cx and dx registers
	call	initialize

;---------------------------------------------------------------------
start_turn:
	nop
	;call	update_statusbar
	call	plystatus
	jmp	start_turn
MASM
	;Check if in jail. If yes can skip.
	cmp	curr_jailed,0
	jne	@s_t_1
	
	call	roll_dice
	
	call	move_piece

	call	action
@s_t_1:	
	call	end_turn
	
	jmp	start_turn
	
;---------------------------------------------------------------------
wait_for_exit:
	mov	ah, 0bh
	int	21h

	cmp	al, 0ffh
	jne	wait_for_exit
;---------------------------------------------------------------------



;--------------------------------------------------------------------------

;}}


;==========================================================================
;                               Procedures
;=========================================================================={{

;--------------------------------------------------------------------------
; clears registers
;--------------------------------------------------------------------------{{{
clear_reg	proc	near

	xor	ax, ax
	xor	bx, bx
	xor	cx, cx
	xor	dx, dx

	ret

clear_reg	endp
;}}}


;--------------------------------------------------------------------------
; Updates status bar
;--------------------------------------------------------------------------{{{
IDEAL
PROC	update_statusbar
;Update status bar depending on which player's turn.
	
	;Determine current player.
	;message	dashed
	xor	bx,bx
	mov	bl, [curr_plyr]	
	cmp	bl,0
	jne	@@playerB
	
	;message	plyrA_msg
	jmp	@@ud_sb_1
	
@@playerB:	;message	plyrB_msg
	
@@ud_sb_1:
	;Update "Current" variables.
	
	mov	di,bx
	add	di,di
	mov	ax,[plyrA_cash + di]
	mov	[curr_cash],ax
	mov	ax,[plyrA_assets + di]
	mov	[curr_assets],ax
	
	;Checks if player is in jail.
	
	mov	al,[plyrA_jailed + bx]
	mov	[curr_jailed],al
	cmp	al,0
	je	@@ud_sb_done	

	;If in jail:
		;message	jailed_msg
			
	;If not in jail:
	
@@ud_sb_done:	
	ret

ENDP	update_statusbar
;}}}
MASM

;--------------------------------------------------------------------------
; User presses key to roll dice. Saves random number from 1-6  in dice_roll.
;--------------------------------------------------------------------------{{{
roll_dice	proc	near
		
				;Puts current space into curr_space.
	mov	al,plyrA_space
	cmp	curr_plyr,0
	je	@r_d_1
	mov	al,plyrB_space	
@r_d_1:	
	message	currspace_msg	;Print current space (found in al above)
	
	mov	curr_space,al
	mov	ah,00h
	call	dispx		;Print decimal of ax.
	message	lbr
	
	message	roll_msg
	
	@wait_for_dice:		;Wait for user keypress.
		
	mov	ah, 0bh
	int	21h
	cmp	al, 0ffh
	jne	@wait_for_dice

	mov	ah, 0ch		;clear keyboard buffer
	int	21h
	
	message	result_msg
	
	call 	rand		;Random number stored in ax.
	call	dispx		;Print decimal of ax.
	message	lbr
	
	mov	dice_roll,al	

	ret

roll_dice	endp
;}}}


;--------------------------------------------------------------------------
; Move your piece on the board. Updates GUI. Updates curr_space. 
;--------------------------------------------------------------------------{{{
move_piece	proc	near

	mov	al,curr_space	;Add dice roll to curr_space and correct overshoot.
	add	al,dice_roll
	cmp	al,spaces
	jb	@m_p_1
	sub	al,spaces
	
@m_p_1:	
				;Update player A or B location data.
	cmp	curr_plyr,0
	jne	@m_p_2
	mov	plyrA_space,al
	jmp	@m_p_3
@m_p_2:	
	mov	plyrB_space,al			


@m_p_3:				;at this point, al contains new space id.
	message	newspace_msg	;Print new space message.
	
	mov	ah,00h
	call	dispx		;Print decimal of ax.
	message	lbr
	
	mov	curr_space,al
	
	
	
	;Debug! Debug! Move to Any Space!
	;mov	ah, 0ch		;clear keyboard buffer
	;int	21h
@debug:	mov	ah,7 		;read in letter without echo
	int	21h
	cmp	al, 'a'
	jl	@debug
	cmp	al, 'x'
	ja	@debug
	sub	al,97d
	cmp	curr_plyr,0
	jne	@debug2
	mov	plyrA_space,al
	jmp	@debug3
@debug2:	
	mov	plyrB_space,al
@debug3:	mov	curr_space,al
	;End Debug! Debug!
	
	ret

move_piece	endp
;}}}


;--------------------------------------------------------------------------
; Based on space ID, take action.
;--------------------------------------------------------------------------{{{
action	proc	near

	;get space type
	
	message	spacetype_msg
	
	xor	bx,bx
	mov	bl,curr_space
	mov	al,space_type[bl]
	
	mov	ah,00h
	call	dispx		;Print decimal of ax.
	message	lbr
	
	mov	curr_type,al	;Updates memory
	
	
	;get space name
	
	mov	al,curr_space
	mov	bl,11d
	mul	bl
	
	xor	dh,dh
	lea	dx,space_name
	add	dx,ax
	mov	ah, 09h
	int	21h
	
	;go to action based on space type.
	
	cmp	curr_type,0
	jne	@act_1
	call	action_go
	
@act_1:	cmp	curr_type,1
	jne	@act_2
	call	action_property	
	
@act_2:	cmp	curr_type,2
	jne	@act_3
	call	action_util

@act_3:	cmp	curr_type,3
	jne	@act_4
	call	action_jail

@act_4:	cmp	curr_type,4
	jne	@act_5
	call	action_chance
@act_5:	
	
	;user input. quit.
	
	message	dashed
	
	mov	ah, 0ch		;clear keyboard buffer
	int	21h
	mov	ah,7 		;read in number
	int	21h
	cmp	al, 'q'		;check that it is q
	jne	@cont
	call	exit
@cont:	
	ret

action	endp
;}}}


;--------------------------------------------------------------------------
; Ends turn.
;--------------------------------------------------------------------------{{{
end_turn	proc	near

	mov	bl,curr_plyr
	xor	bl,1
	mov	curr_plyr,bl
	xor	bh,bh
	
	;If money is zero, end game immediately.
	
	cmp	plyrA_cash[bx],0
	jne	@e_t_1
		call	exit
	
@e_t_1:	
	;If in jail, decrement.
	
	cmp	plyrA_jailed[bx],0
	je	@e_t_end
		dec	plyrA_jailed[bx]
@e_t_end:
	
	message	lbr
	ret

end_turn	endp
;}}}



;--------------------------------------------------------------------------
; Exit game. Show who the winner is.
;--------------------------------------------------------------------------{{{
exit	proc	near

	mov	bl,curr_plyr
	xor	bh,bh

	message	exit_msg
	
	message	dashed
	message	plyrA_msg
	message	dashed
	
	message	cash_msg
	mov	ax,plyrA_cash
	call	dispx
	message	lbr
	
	message	assets_msg
	mov	ax,plyrA_assets
	call	dispx
	message	lbr
	
	message	dashed
	message	plyrB_msg
	message	dashed
	
	message	cash_msg
	mov	ax,plyrB_cash
	call	dispx
	message	lbr
	
	message	assets_msg
	mov	ax,plyrB_assets
	call	dispx
	message	lbr
	message	lbr
	
	message	winner_msg	;The winner is..
	mov	ax,plyrA_cash
	cmp	ax,plyrB_cash
	ja	@a_winner
	jb	@b_winner
	
	;No-one won.
	message	tie_msg
	jmp	@exit
	
@a_winner:	;A won.
	message	plyrA_msg
	message	score_msg
	mov	ax,plyrA_assets
	call	dispx
	message	lbr	
	jmp	@exit
@b_winner:	;B won.
	message	plyrB_msg
	message	score_msg
	mov	ax,plyrB_assets
	call	dispx
	message	lbr
@exit:	
	;pop	ax
	;mov	ah, 00h		; set back to original video mode
	;int	10h

	mov	ah, 0ch		; clear keyboard buffer
	int	21h

	mov	ah, 4ch		; exit program
	int	21h

	;No ret here.

exit	endp
;}}}



;The following procedures relate to actions upon landing in a new space.

;--------------------------------------------------------------------------
; Collect money on passing GO.
;--------------------------------------------------------------------------{{{
action_go	proc	near

	message	go_msg
	mov	bx,50d
	call	add_cash
	;update GUI
	ret

action_go	endp
;}}}

;--------------------------------------------------------------------------
; If space is property, check who the owner is before going to sub-action.
;--------------------------------------------------------------------------{{{
action_property	proc	near

	;get space owner
	
	message	currowner_msg
	
	xor	bx,bx
	mov	bl,curr_space
	mov	al,space_owner[bl]
	
	mov	ah,00h
	call	dispx		;Print decimal of ax.
	message	lbr
	
	mov	curr_owner,al	;Updates memory
	
	
	cmp	curr_owner,2	;No-one owns the space.
	jne	@a_p_1
	call	action_property_buy
	jmp	@a_p_3
	
@a_p_1:				;If someone owns the space, check who owns the space.
	mov	ah,curr_plyr	;Compare current player with current owner.
	cmp	ah,al
	jne	@a_p_2
	
	call	action_property_upgrade	;Current player owns space.
	jmp	@a_p_3
	
@a_p_2:	call	action_property_rent	;Opponent owns space.
	jmp	@a_p_3
	
@a_p_3:
	
	
	ret

action_property	endp
;}}}

;--------------------------------------------------------------------------
; If space is utility, check who is owner before rent/do nothing.
;--------------------------------------------------------------------------{{{
action_util	proc	near

	push	ax
	push	bx
	
	message	utility_msg
	
	;get space owner
	
	message	currowner_msg
	
	xor	bx,bx
	mov	bl,curr_space
	mov	al,space_owner[bl]
	
	mov	ah,00h
	call	dispx		;Print decimal of ax.
	message	lbr
	
	mov	curr_owner,al	;Updates memory
	
	
	cmp	curr_owner,2	;No-one owns the space.
	jne	@a_u_1
	call	action_util_buy
	jmp	@a_u_3
	
@a_u_1:				;If someone owns the space, check who owns the space.
	mov	ah,curr_plyr	;Compare current player with current owner.
	cmp	ah,al
	jne	@a_u_2
	
	message	utilown_msg	;You own the space.
	jmp	@a_u_3
	
@a_u_2:	call	action_util_rent	;Opponent owns space.

	jmp	@a_u_3
	
@a_u_3:
	pop	bx
	pop	ax
	
	ret

action_util	endp
;}}}
;--------------------------------------------------------------------------
; Jail. 
;--------------------------------------------------------------------------{{{
action_jail	proc	near
	
	xor	bx,bx
	message	jail_msg
	mov	bl,curr_plyr
	mov	plyrA_jailed[bx],2
	;update GUI
	ret

action_jail	endp
;}}}
;--------------------------------------------------------------------------
; Chance.
;--------------------------------------------------------------------------{{{
action_chance	proc	near

	call	rand	
	cmp	ax,1
	je	@c_badluck
	
	;Good luck!
	add	ax,ax
	add	ax,ax
	message	goodluck_msg
	call	dispx
	message	lbr
	mov	bx,ax
	call	add_cash
	jmp	@c_end
@c_badluck:
	;Bad luck!
	message	badluck_msg
	mov	bx,50
	call	dec_cash
@c_end:		
	;update GUI
	ret

action_chance	endp
;}}}

; The following are sub-procedures for when player lands on a property (buy/upgrade/rent)

;--------------------------------------------------------------------------
; Asks if want to buy space with no owner. 
;--------------------------------------------------------------------------{{{
action_property_buy	proc	near



	;Ask player if want to buy. Give price.
	
	message	ask_buy_msg	
	
	xor	ax,ax
	xor	bx,bx
	mov	bl,curr_space
	mov	al,buy_price[bl]	
	call	dispx
	message	lbr
	
	;User input y/n.
	
	call	yes_no
	cmp	flag_var,1
	jne	@a_p_b_1
	
	;if Yes:
	
		mov	bx,ax		;decrease cash
		call	dec_cash
		call	add_assets
		;update owner
		mov	bl,curr_space
		mov	al,curr_plyr
		mov	space_owner[bl],al
		;update GUI
	
	;if No:
	@a_p_b_1:	
	

	
	ret

action_property_buy	endp
;}}}


;--------------------------------------------------------------------------
; Asks if want to upgrade own space (provided not fully upgraded)
;--------------------------------------------------------------------------{{{
action_property_upgrade	proc	near

	;ask player if want to upgrade. give price also.
	
	mov	bl,curr_space
	mov	al,space_level[bl]
	mov	curr_level,al
	
	cmp	al,2		;If hotel, cannot upgrade any more.
	jne	@a_p_u_1
	message	full_upg_msg
	jmp	@a_p_u_done

@a_p_u_1:			;If not hotel, still can upgrade.
	message	ask_upg_msg
	
	xor	ax,ax
					;BL already contains curr_space.
	mov	al,upgrade_price[bl]	;Give price.	
	call	dispx
	message	lbr
	
	;;User input y/n.
	
	call	yes_no
	cmp	flag_var,1
	jne	@a_p_u_done
	
	;if Yes:
	
		;amt of money put into bx
		mov	bx,ax
		call	dec_cash
		;upgrade space
		mov	bl,curr_space
		mov	al,curr_level
		inc	al
		mov	space_level[bl],al	
		
		;update GUI
	
	;if No:
	
@a_p_u_done:	
	
	ret

action_property_upgrade	endp
;}}}


;--------------------------------------------------------------------------
; Pay rent. No choice! 
;--------------------------------------------------------------------------{{{
action_property_rent	proc	near
	
	xor	ax,ax
	xor	bx,bx
	xor	cx,cx
	
	message	spacelevel_msg	;Give level.
	mov	bl,curr_space
	mov	al,space_level[bl]
	call	dispx
	message	lbr
	mov	cl,al
	
	mov	al,rent_price[bl]	
				;at this point, ax contains rent price.
	
	cmp	cl,0
	je	@a_p_r_1
	add	ax,ax
	cmp	cl,1
	je	@a_p_r_1
	add	ax,ax
@a_p_r_1:	
	
	message	pay_rent_msg	;Give rent price.
	call	dispx
	message	lbr		
				;at this point, ax contains rent price.
	;amt of money put into bx
	mov	bx,ax
	call	dec_cash
	;increase opponent's cash
	xor	curr_plyr,1
	call	add_cash
	xor	curr_plyr,1
	;update GUI
	ret

action_property_rent	endp
;}}}


; The following is sub-procedure for when player lands on a utility.

;--------------------------------------------------------------------------
; Buy utility.
;--------------------------------------------------------------------------{{{
action_util_buy	proc	near

	;ask player if want to buy utility. Also give price.
	
	message	ask_buy_msg
	
	xor	ax,ax
	xor	bx,bx		;Give price.
	mov	bl,curr_space
	mov	al,buy_price[bl]	
	call	dispx
	message	lbr
	
	;;User input y/n.
	
	call	yes_no
	cmp	flag_var,1
	jne	@a_u_b_done
	
	;if Yes:
	
		mov	bx,ax		;decrease cash
		call	dec_cash
		call	add_assets
		;update owner
		mov	bl,curr_space
		mov	al,curr_plyr
		mov	space_owner[bl],al
		;update number of utilities owned
		mov	bl,al		;move curr_plyr to bl
		inc	plyrA_util[bl]
		;update GUI
		
	;if No:
@a_u_b_done:	
	ret

action_util_buy	endp
;}}}

IDEAL
;--------------------------------------------------------------------------
; Update Game Play Status
;--------------------------------------------------------------------------{{{
PROC	plystatus

	pushad

	box	32, 126, 520, 637, black
	cursor	2, 66
	message	turn_msg
	cursor	3, 66
	cmp	[curr_plyr], 0
	je	@@10
	message	plyr2name
	jmp	@@20
@@10:
	message	plyr1name
@@20:
	cursor	4, 66
	message	cash_msg
	cursor	5, 66
	mov	ax, OFFSET outbuff
	mov	di, ax
	xor	eax, eax
	mov	ax, [curr_cash]
	mov	ecx, 1
	call	BinToAsc
	call	StrWrite
	cursor	6, 66
	message	asset_msg
	cursor	7, 66
	mov	ax, OFFSET outbuff
	mov	di, ax
	xor	eax, eax
	mov	ax, [curr_assets]
	mov	ecx, 1
	call	BinToAsc
	call	StrWrite

	popad
	ret

ENDP	plystatus
;}}}
MASM

;--------------------------------------------------------------------------
; Pay Rent for utility to opponent.
;--------------------------------------------------------------------------{{{
action_util_rent	proc	near

	message	pay_rent_msg
	
	;Calculate amount of rent to pay. Count opponent's utilities.
	
	xor	bx,bx
	mov	bl,curr_plyr
	xor	bl,1
	mov	cl,plyrA_util[bl]

	mov	bx,10		;Base rent for utilities is 10.
	cmp	cl,1
	je	@a_u_r_1
	add	bx,bx
	cmp	cl,2
	je	@a_u_r_1
	add	bx,bx
@a_u_r_1:
	mov	ax,bx
	call	dispx
	message	lbr		
				;bx already contains rent to decrease.
	call	dec_cash
	
	;increase opponent's cash
	xor	curr_plyr,1
	call	add_cash
	xor	curr_plyr,1
	
	;update GUI
	ret

action_util_rent	endp
;}}}

; Cash procedures

;--------------------------------------------------------------------------
;Increase cash. Amount of cash to increase stored in bx.
;--------------------------------------------------------------------------{{{
add_cash	proc	near
	
	push	ax
	
	mov	ax,plyrA_cash		;Move current player's cash into ax.
	cmp	curr_plyr,0
	je	@a_c_1
	mov	ax,plyrB_cash	
@a_c_1:	
	
	add	ax,bx
	jnc	@a_c_notcarry
	message	overflow_msg
	mov	ax,0ffffh
					;At this point, ax contains new cash amount.
@a_c_notcarry:	
	cmp	curr_plyr,0		;Update current player's cash.
	jne	@a_c_2
	mov	plyrA_cash,ax
	;update GUI
	jmp	@a_c_3
@a_c_2:	
	mov	plyrB_cash,ax
	;update GUI

@a_c_3:	
	pop	ax	
	
	ret

add_cash	endp
;}}}

;--------------------------------------------------------------------------
;Decrease cash. Amount of cash to decrease stored in bx.
;--------------------------------------------------------------------------{{{
dec_cash	proc	near
	
	push	ax
	
	mov	ax,plyrA_cash		;Move current player's cash into ax.
	cmp	curr_plyr,0
	je	@d_c_1
	mov	ax,plyrB_cash	
@d_c_1:	
	
	sub	ax,bx
	jnc	@d_c_notcarry
	message	overflow_msg
	mov	ax,0000h
					;At this point, ax contains new cash amount.
@d_c_notcarry:	
	cmp	curr_plyr,0		;Update current player's cash.
	jne	@d_c_2
	mov	plyrA_cash,ax
	;update GUI
	jmp	@d_c_3
@d_c_2:	
	mov	plyrB_cash,ax
	;update GUI

@d_c_3:	
	pop	ax	
	
	ret

dec_cash	endp
;}}}


;--------------------------------------------------------------------------
;Increase assets. Amount of assets to increase stored in bx.
;--------------------------------------------------------------------------{{{
add_assets	proc	near
	
	push	ax
	
	mov	ax,plyrA_assets		;Move current player's cash into ax.
	cmp	curr_plyr,0
	je	@a_a_1
	mov	ax,plyrB_assets	
@a_a_1:	
	
	add	ax,bx
	jnc	@a_a_notcarry
	message	overflow_msg
	mov	ax,0ffffh
					;At this point, ax contains new cash amount.
@a_a_notcarry:	
	cmp	curr_plyr,0		;Update current player's cash.
	jne	@a_a_2
	mov	plyrA_assets,ax
	;update GUI
	jmp	@a_a_3
@a_a_2:	
	mov	plyrB_assets,ax
	;update GUI

@a_a_3:	
	pop	ax	
	
	ret

add_assets	endp
;}}}





;}}


; Temp input procedure

;--------------------------------------------------------------------------
;Temp wait for input y/n. Returns 1 in flag_var if y, 0 if n.
;--------------------------------------------------------------------------{{{
yes_no	proc	near
	
	push	ax

@y_n_0:
	mov	ah, 0ch		;clear keyboard buffer
	int	21h
	mov	ah,7 		;read in number without echo
	int	21h
	cmp	al, 'y'		;check that it is y
	je	@y_n_1
	cmp	al, 'n'		;check that it is n
	je	@y_n_2
	jmp	@y_n_0

@y_n_1:	mov	flag_var,1
	jmp	@y_n_end
@y_n_2:	mov	flag_var,0
	
@y_n_end:
	pop	ax
		
	ret	

yes_no	endp
;}}}

IDEAL
;--------------------------------------------------------------------------
; Update Game Play Status
;--------------------------------------------------------------------------{{{
PROC	initialize
	mov	ah, 0fh			; get current video mode
	int	10h
	push	eax

	mov     ah, 00h			; set resolution to 640 x 480
	mov     al, 12h			; 16 colors
	int     10h

	call	welcome
	call	interface
	
	ret
ENDP	initialize
;}}}


;--------------------------------------------------------------------------
; welcome message
;--------------------------------------------------------------------------{{{
PROC	welcome
	call	clear_reg

        pushad				; saves previous contents of ax into stack

        cursor  12, 25			; display "Welcome to the Word of Fortune Game"
	message wel_msg
        cursor  14, 29			; display "Press any key to continue"
	message key_msg

wait_for_key:
	mov     ah, 0bh			; wait for any key to be pressed
	int     21h

	cmp     al, 0ffh
	jne     wait_for_key

	call clrscrn

	cursor  12, 25
	message	askname1
	mov	ax, OFFSET plyr1name
	mov	di, ax
	mov	cl, 019
	call	StrRead
	
	cursor	15, 25
	message	askname2
	mov	ax, OFFSET plyr2name
	mov	di, ax
	mov	cl, 19
	call	StrRead	

done_wel:
	call clrscrn
	; clear message area

        mov     ah, 0ch			; clear keyboard buffer
        int     21h

	popad				; retrieves contents into ax from the stack
	
	ret

ENDP	welcome
;}}}

;--------------------------------------------------------------------------
; draws interface
;--------------------------------------------------------------------------{{{
PROC	interface

	pushad
	call    game_title              ; display title of game
	call    squares                 ; display squares where the alphabets sit
	mov	ax, 01h
	int	33h
	popad
	ret

ENDP	interface
;}}}

;--------------------------------------------------------------------------
; displays title
;--------------------------------------------------------------------------{{{
PROC	game_title

        ctrmsg wof_msg, 0, 39					; displays "Name of the Game"
	
        change_color    00, 50, 0, 640, lightgray, lightcyan	; changes color of titles

	ret

ENDP	game_title
;}}}

;--------------------------------------------------------------------------
; alignment for squares
;--------------------------------------------------------------------------{{{
PROC	squares

	; begin game grid
        hline   25, 1, 220, white
        hline   25, 293, 512, white

	hline	111, 1, 512, white

	hline	197, 1, 74, white
	hline	197, 147, 366, white
	hline	197, 439, 512, white

	hline	283, 1, 74, white
	hline	283, 147, 366, white
	hline	283, 439, 512, white

	hline	369, 1, 512, white

	hline	455, 1, 220, white
	hline	455, 293, 512, white

	vline	25, 455, 1, white
	vline	25, 455, 74, white

	vline	25, 197, 147, white
	vline	283, 455, 147, white
	vline	25, 197, 220, white
	vline	283, 455, 220, white
	vline	25, 197, 293, white
	vline	283, 455, 293, white
	vline	25, 197, 366, white
	vline	283, 455, 366, white

	vline	25, 455, 439, white
	vline	25, 455, 512, white

	; begin game heading color
	box	370, 393, 367, 439, lightblue
	box	370, 393, 294, 366, lightblue
	box	284, 307, 294, 366, lightblue
	box	284, 307, 148, 220, magenta
	box	370, 393, 148, 220, magenta
	box	370, 393, 75, 147, magenta
	box	284, 307, 2, 74, red
	box	198, 220, 2, 74, red
	box	112, 135, 2, 74, red
	box	26, 49, 75, 147, brown
	box	26, 49, 148, 220, brown
	box	112, 135, 148, 220, brown
	box	112, 135, 294, 366, green
	box	26, 49, 294, 366, green
	box	26, 49, 367, 439, green
	box	112, 135, 440, 512, blue
	box	198, 220, 440, 512, blue
	box	284, 307, 440, 512, blue

	; begin action window
	hline	29, 518, 639, yellow
	hline	451, 518, 639, yellow
	vline	29, 451, 518, yellow
	vline	29, 451, 639, yellow

	; begin town names
	ctrmsg space_1, 25, 60
	ctrmsg space_2, 25, 50
	ctrmsg space_3, 25, 41
	ctrmsg space_4, 20, 41
	ctrmsg space_5, 20, 32
	ctrmsg space_6, 20, 23
	ctrmsg space_7, 25, 23
	ctrmsg space_8, 25, 14
	ctrmsg space_9, 25, 5
	ctrmsg space_10, 20, 5
	ctrmsg space_11, 14, 5
	ctrmsg space_12, 9, 5
	ctrmsg space_13, 4, 5
	ctrmsg space_14, 4, 14
	ctrmsg space_15, 4, 23
	ctrmsg space_16, 9, 23
	ctrmsg space_17, 9, 32
	ctrmsg space_18, 9, 41
	ctrmsg space_19, 4, 41
	ctrmsg space_20, 4, 50
	ctrmsg space_21, 4, 60
	ctrmsg space_22, 9, 60
	ctrmsg space_23, 14, 60
	ctrmsg space_24, 20, 60

	ctrmsg prog_name,15, 32

        ret

ENDP	squares
;}}}

;--------------------------------------------------------------------------
; Clears Screen (FAST!)
;--------------------------------------------------------------------------{{{
PROC	clrscrn

        pushad

	mov     ah, 00h			; set resolution to 640 x 480
	mov     al, 12h			; 16 colors
	int     10h

	popad
	ret

ENDP	clrscrn
;}}}

;--------------------------------------------------------------------------
; Output Message to Status Bar
; Input:
;	di: pointer to start of null terminated char string
;--------------------------------------------------------------------------{{{
PROC	outmsg

        pushad

	box     456, 480, 0, 640, black
	call	StrLength
	mov	ax, cx
	div	[two]
	mov	bx, 39
	sub	bx, ax
	cursor  29, bl
	call	StrWrite

	popad
	ret

ENDP	outmsg
;}}}

;]
end	start

